# Build stage
FROM golang:1.18 AS builder

# Set the working directory
WORKDIR /src

# Copy go mod and sum files
COPY go.mod go.sum ./

# Download all dependencies
RUN go mod download

# Copy the source code
COPY . .

# Copy the Makefile
COPY Makefile .

# Build the application
RUN make build DISTPATH=/app

# Final stage
FROM alpine:latest

# Install ca-certificates for HTTPS requests
RUN apk --no-cache add ca-certificates

WORKDIR /root/

# Copy the binary from the builder stage
COPY --from=builder /app/connectgo .

# Command to run the executable
CMD ["./connectgo"]